setwd("D:/1大学生活/大三下/zxy/R语言/实践五")
ADdata = read.csv("ADdata.csv",row.names = 1)

#提取分组信息
a = grep("asym",colnames(ADdata))
b = grep("ad",colnames(ADdata))
c = grep("ctl",colnames(ADdata))

#将分组信息与ADdata对应
group = NA
group[a] = "asym"
group[b] = "ad"
group[c] = "ctl"

#对数化
ADdata[ADdata == 0] = NA
ADdata = log(ADdata)

#建立结果数据框
result = data.frame(Protein_ID = rownames(ADdata),P_Value = NA)

#循环判断各组数据是否至少3个样本有数值
#对于判定结果进行方差分析
for(i in 1:100)
{
  prox = unlist(ADdata[i,])
  a_sum = sum(!is.na(ADdata[i,a]))
  b_sum = sum(!is.na(ADdata[i,b]))
  c_sum = sum(!is.na(ADdata[i,c]))
  if(a_sum>2 & b_sum>2 & c_sum>2)
  {
    test = oneway.test(prox~group,ADdata[i,])
    result$P_Value[i] = test$p.value
  }
}
write.csv(result, "result.csv", row.names = FALSE)
